﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.ViewModels;

namespace Chefbook.UserActions
{
    /// <summary>
    /// An action to remove a recipe from a category
    /// </summary>
    public class RemoveIngredientAction : UserActionBase
    {
        private IngredientViewModel ingredientToRemove;
        private RecipeViewModel recipeToRemoveFrom;

        /// <summary>
        /// Creates a new action to remove a ingredient from a recipe
        /// </summary>
        /// <param name="ingredientToRemove">The ingredient to removee</param>
        /// <param name="recipeToRemoveFrom">The recipe to remove from</param>
        public RemoveIngredientAction(IngredientViewModel ingredientToRemove, RecipeViewModel recipeToRemoveFrom)
            : base()
        {
            this.ingredientToRemove = ingredientToRemove;
            this.recipeToRemoveFrom = recipeToRemoveFrom;
        }

        /// <summary>
        /// Removes the ingredient from the specified recipe
        /// </summary>
        public override void DoAction()
        {
            base.DoAction();
            recipeToRemoveFrom.RemoveIngredient(ingredientToRemove);
        }

        /// <summary>
        /// Returns the ingredient to the recipe it was removed from
        /// </summary>
        public override void UndoAction()
        {
            base.UndoAction();
            recipeToRemoveFrom.AddIngredient(ingredientToRemove);
        }

        /// <summary>
        /// Returns a user-friendly string describing the action
        /// </summary>
        /// <returns>A user-friendly string describing the action</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.InvariantCulture, "Remove Ingredient '{0}' from Recipe '{1}'", ingredientToRemove, recipeToRemoveFrom);
        }
    }
}
